package com.stylefeng.guns.modular.model.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import net.bytebuddy.asm.Advice;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.StaActCentre;
import com.stylefeng.guns.modular.model.service.IStaActCentreService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * model控制器
 *
 * @author fengshuonan
 * @Date 2018-08-01 18:02:37
 */
@Controller
@RequestMapping("/staActCentre")
public class StaActCentreController extends BaseController {

    private String PREFIX = "/model/staActCentre/";

    @Autowired
    private IStaActCentreService staActCentreService;


    /*
   站点和路线的中间表   有时间和站点id和路线id
    */
    @RequestMapping("/sta")
    public Object staActCentre() {


        return null;
    }

    @RequestMapping("/addsite")
    public Object addsite(HttpServletRequest request, HttpServletResponse response) {


        return null;
    }

    /*
    生成线路
     */
    @RequestMapping("/actualroute")
    public Object actualroute(HttpServletRequest request, HttpServletResponse response) {
        String site1 = "120.34956,36.07619";
        String site2 = "120.36593,36.10616";

        return null;
    }

    /**
     * 跳转到model首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "staActCentre.html";
    }

    /**
     * 跳转到添加model
     */
    @RequestMapping("/staActCentre_add")
    public String staActCentreAdd() {
        return PREFIX + "staActCentre_add.html";
    }

    /**
     * 跳转到修改model
     */
    @RequestMapping("/staActCentre_update/{staActCentreId}")
    public String staActCentreUpdate(@PathVariable Integer staActCentreId, Model model) {
        StaActCentre staActCentre = staActCentreService.selectById(staActCentreId);
        model.addAttribute("item", staActCentre);
        LogObjectHolder.me().set(staActCentre);
        return PREFIX + "staActCentre_edit.html";
    }

    /**
     * 获取model列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return staActCentreService.selectList(null);
    }

    /**
     * 新增model
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(StaActCentre staActCentre) {
        staActCentreService.insert(staActCentre);
        return SUCCESS_TIP;
    }

    /**
     * 删除model
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer staActCentreId) {
        staActCentreService.deleteById(staActCentreId);
        return SUCCESS_TIP;
    }

    /**
     * 修改model
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(StaActCentre staActCentre) {
        staActCentreService.updateById(staActCentre);
        return SUCCESS_TIP;
    }

    /**
     * model详情
     */
    @RequestMapping(value = "/detail/{staActCentreId}")
    @ResponseBody
    public Object detail(@PathVariable("staActCentreId") Integer staActCentreId) {
        return staActCentreService.selectById(staActCentreId);
    }

    @RequestMapping(value = "/siteByLine")
    @ResponseBody
    public Object selectSiteByRouteId(@RequestParam Integer lineId) {
        return staActCentreService.selectSiteByRouteId(lineId);
    }
}
